package net.lainiao.morethread.Chapter4.demo11;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * Created by Administrator on 2017/3/4.
 */
public class Main {
    public static void main(String[] args) {
        RejectedTaskController rejectedTaskController=new RejectedTaskController();
        ThreadPoolExecutor executor=(ThreadPoolExecutor) Executors.newCachedThreadPool();
        executor.setRejectedExecutionHandler(rejectedTaskController);
        System.out.println("Main Starting");
        for (int i = 0; i < 3; i++) {
            Task task=new Task("Task"+i);
            executor.submit(task);
        }
        System.out.println("Main: Shutdown Executor!");
        executor.shutdown();
        Task shutDownTask=new Task("ShutDownTask");
        executor.submit(shutDownTask);
        System.out.println("Main End ");
    }
}
